/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    gpio.c
  * @brief   This file provides code for the configuration
  *          of all used GPIO pins.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "gpio.h"

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/*----------------------------------------------------------------------------*/
/* Configure GPIO                                                             */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/** Configure pins as
        * Analog
        * Input
        * Output
        * EVENT_OUT
        * EXTI
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOE_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOE, Short_CTRL_PE5_Pin|QuieCur_CTRL_O_PE6_Pin|Test_pin_Pin|Output11_O_PE13_Pin
                          |CAN_Silent_O_PE10_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOC, OverCurCtr_O_LL_PC13_Pin|OUT7_PC6_Pin|Output10_O_PC12_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|OUT10_PD13_Pin|OUT9_PD14_Pin|OUT8_PD15_Pin
                          |Output9_O_PD0_Pin|OUT6_PD1_Pin|OUT3_PD4_Pin|OUT2_PD5_Pin
                          |OUT1_PD6_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pins : PEPin PEPin PEPin PEPin
                           PEPin */
  GPIO_InitStruct.Pin = OverCurP_I_LL_PE4_Pin|SW1_Pin|SW2_Pin|SW3_Pin
                          |INPUT1_PE0_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /*Configure GPIO pins : PEPin PEPin PEPin PEPin */
  GPIO_InitStruct.Pin = Short_CTRL_PE5_Pin|QuieCur_CTRL_O_PE6_Pin|Test_pin_Pin|Output11_O_PE13_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /*Configure GPIO pins : PCPin PCPin PCPin */
  GPIO_InitStruct.Pin = OverCurCtr_O_LL_PC13_Pin|OUT7_PC6_Pin|Output10_O_PC12_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pins : PD12 PDPin PDPin PDPin
                           PDPin PDPin PDPin PDPin
                           PDPin */
  GPIO_InitStruct.Pin = GPIO_PIN_12|OUT10_PD13_Pin|OUT9_PD14_Pin|OUT8_PD15_Pin
                          |Output9_O_PD0_Pin|OUT6_PD1_Pin|OUT3_PD4_Pin|OUT2_PD5_Pin
                          |OUT1_PD6_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /*Configure GPIO pins : PCPin PCPin */
  GPIO_InitStruct.Pin = INPUT6_PC8_Pin|PhotoElectricSW_I_PC10_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pins : PAPin PAPin PAPin */
  GPIO_InitStruct.Pin = START2_TEST_I_PA9_Pin|MANUAL_RESET_I_PA10_Pin|START1_TEST_I_PA15_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = INPUT5_PD7_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(INPUT5_PD7_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : PBPin PBPin PBPin */
  GPIO_InitStruct.Pin = INPUT4_PB3_Pin|INPUT3_PB4_Pin|INPUT2_PB7_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = CAN_Silent_O_PE10_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(CAN_Silent_O_PE10_GPIO_Port, &GPIO_InitStruct);

}

/* USER CODE BEGIN 2 */
void ctrl_gpio_init(uint8_t ctrl_sta)
{
  #if 1
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    HAL_GPIO_DeInit(GPIOD, Output9_O_PD0_Pin|OUT3_PD4_Pin|OUT2_PD5_Pin|OUT1_PD6_Pin);
  if (0 == ctrl_sta)
  {
    /* 切换为输入模式，进入低功耗模式 */
    GPIO_InitStruct.Pin = Output9_O_PD0_Pin|OUT3_PD4_Pin|OUT2_PD5_Pin|OUT1_PD6_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
    HAL_GPIO_WritePin(GPIOC, Output10_O_PC12_Pin, GPIO_PIN_RESET);
  }else if (1 == ctrl_sta)
  {
    /* 切换为输出模式，进入正常模式 */
    /*Configure GPIO pin Output Level */
    
    HAL_GPIO_WritePin(GPIOD, Output9_O_PD0_Pin|OUT3_PD4_Pin|OUT2_PD5_Pin
                          |OUT1_PD6_Pin, GPIO_PIN_RESET);
    GPIO_InitStruct.Pin = Output9_O_PD0_Pin|OUT3_PD4_Pin|OUT2_PD5_Pin|OUT1_PD6_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  }
  #endif
}
/* USER CODE END 2 */
